﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MyUtils
{
    //所有单例自身的初始化方法自己手动调用
    public abstract class Singleton<T> where T : class, new()
    {
        protected static T _instance = null;
        private static readonly object syslock = new object();

        public static T Instance
        {
            get
            {
                if (null == _instance)
                {
                    lock (syslock)
                    {
                        if (null == _instance)
                        {
                            _instance = new T();
                        }
                    }
                }
                return _instance;
            }
        }

        protected Singleton()
        {
            if (null != _instance)
            {
                Debug.LogError("This " + (typeof(T)).ToString() + " Singleton Instance is not null !!!");
            }
        }

        public abstract bool Init();
    }
}
